<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
    }
    
    html {
        width: 100%;
        height: 100%;
    }
    
    body {
        width: 100%;
        height: 2400px;
    }
    
    div {
        width: 50px;
        height: 50px;
        background-color: pink;
        position: fixed;
        right: 30px;
        bottom: 30px;
        display: none;
    }
</style>

<body>
    <div class="gotop">点击返回顶部</div>

    <script src="./jquery/jquery.min.js"></script>
    <script>
        function fn() {
            var heigth = $(this).scrollTop()
            if (heigth >= 500) {
                $('.gotop').fadeIn()
            } else {
                $('.gotop').fadeOut()
            }
        }
        fn()
        $(window).scroll(fn)

        $('.gotop').click(function() {
            $('body,html').animate({
                scrollTop: 0
            }, 1000)
        })
    </script>
</body>

</html>